Skip to content

feat(share): add --force flag to share delete for orphan cleanup - #40

Merged
bfirestone merged 2 commits into
mainfrom
fix/share-delete-oprphans
Apr 30, 2026
Merged

feat(share): add --force flag to share delete for orphan cleanup#40
bfirestone merged 2 commits into
mainfrom
fix/share-delete-oprphans

Conversation

@bfirestone

Copy link
Copy Markdown
Contributor

Summary

  • Add --force / -f to arc share delete so users can prune dead entries from ~/.arc/shares.json when normal delete can't proceed (missing local edit_token, or the server returns 404/403/network errors).
  • Set SilenceUsage: true on shareDeleteCmd so runtime errors no longer dump the cobra help block — matches the existing pattern in cmd/arc/self.go.

Behavior

--force is a client-side cleanup flag. The server still requires a valid edit token to actually delete a share — --force just lets the user prune their own registry when they can't satisfy that requirement.

State Without --force With --force
Bare ID not in shares.json error: "unknown share id" same (intentional)
Local entry, no edit_token error: "no edit_token..." warn, skip server call, remove local entry
Local entry, token, server 2xx delete server + local same
Local entry, token, server 404/403/network error from deleteShare warn, remove local entry

Default behavior is unchanged.

Motivation

Discovered while trying to delete my3xje4x, a share whose server (localhost:7446) was no longer running — the entry was stuck in the registry with no clean removal path.

Test plan

  • arc share delete <id> against an unreachable server now succeeds with --force and warns about the network failure
  • arc share list confirms the orphan is removed
  • arc share delete bogus123 (unknown ID) emits a clean one-line error — no usage dump
  • arc share delete <id> (without --force, valid local + reachable server) still works as before
  • go build ./..., go vet ./cmd/arc/..., go test ./cmd/arc/... all clean

`arc share delete <id>` previously had no recovery path for entries in
~/.arc/shares.json that had become unusable — either the edit_token was
missing locally, or the server returned 404/403/network errors. Both
cases left a dead row in the registry with no way to prune it.

Add a --force / -f flag that turns delete into a best-effort cleanup:
warn instead of erroring when the edit_token is missing (skip server
call), warn instead of erroring when the server delete fails, and always
remove the local registry entry. Default behavior is unchanged.

Also set SilenceUsage on shareDeleteCmd so runtime errors no longer dump
the cobra help block — usage should only print for actual usage errors
(wrong arg count, bad flag), matching the existing pattern in self.go.
- Wrap long error message to satisfy revive line-length-limit (120)
- Discard fmt.Fprintf return values via _, _ = ... and use os.Stderr
  directly to match the existing pattern in share.go / self.go / docs.go
  (revive unhandled-error)
@bfirestone
bfirestone merged commit cec7fd5 into main Apr 30, 2026
3 checks passed
@bfirestone
bfirestone deleted the fix/share-delete-oprphans branch April 30, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant